function Uninstall(){
    for (let i = 0; i < 5; i++) {
        sleep(500);
        Next_Page();
        sleep(500);
        var res = Uninstall_APP();
        if (res) {
            home();
            sleep(1000);
            return true;
        }
    }
    return false;
}

// 不卸载的软件 数组
var not_uninstall = [
    "NekoBox", "易点云测", "AZ测试12", "Telegram", "投屏键盘", "TextNow", "虚拟定位", "设备助手", "Google定位", "Gboard"
]

// 需要卸载的软件 数组
var uninstall_array = [ ]

function Next_Page(){
    var next_page = id("com.huang.autorunmarket:id/goRightView");
    var result = has(next_page);
    if (result) {
        click(next_page);
        logd("进入下一页");
    }
}

function Uninstall_APP(){
    var telegram = text("Telegram").getOneNodeInfo(300);
    if (telegram) {
        var app_list = telegram.parent().siblings();
        var count1 = app_list.length;
        for (let i = 0; i < count1; i++) {
            var app_name = app_list[i].child(1).text;
            var result1 = not_uninstall.includes(app_name);
            if (!result1) {
                uninstall_array.push(app_name);
            }
        }
        sleep(1000);
        var count2 = uninstall_array.length;
        logd("有" + count2 + "个APP需要卸载");
        while (uninstall_array.length > 0) {
            var un_app = text(uninstall_array[0]);
            if (has(un_app)) {
                longClick(un_app);
                logd("点击卸载" + uninstall_array[0]);
                sleep(1000);
                var uninstall = text("卸载");
                if (has(uninstall)) {
                    click(uninstall);
                    sleep(1000);

                    var ask = text("Do you want to uninstall this app?");
                    if (has(ask)) {
                        click(text("OK"));
                        logd(uninstall_array[0] + "卸载成功");
                        uninstall_array.splice(0, 1);
                        sleep(1000);
                    }else {
                        toast("没有弹出卸载提示框");
                        return false;
                    }
                }else {
                    toast("没有弹出卸载按钮");
                    return false;
                }
            }else {
                toast("没有找到" + uninstall_array[0]);
                return false;
            }
        }
        return true;
    }else {
        toast("没有获取到APP列表");
        return false;
    }
}

// Uninstall();